package com.xiaodou.mjf.infrastructure.common.utils;

import java.util.Properties;

import com.xiaodou.mjf.infrastructure.common.context.SpringContextHolder;

/**
 * Created by Rocky on 14/12/21.
 */
public class Global {

    private static String CONSOLE_BASE_DIR = "userfiles.console.basedir";
    private static String PORTAL_BASE_DIR = "userfiles.portal.basedir";
    private static String FTP_HOST="ftp.host";
    private static String FTP_PORT="ftp.port";
    private static String FTP_USER="ftp.user";
    private static String FTP_PASS="ftp.password";
    private static String IMAGE_SERVER="image.server";

    static PropertiesLoader loader = null;
    
    static{
    	String[] profiles = SpringContextHolder.getApplicationContext().getEnvironment().getDefaultProfiles();
        if(profiles != null && profiles.length > 0){
            String fileName = String.format("global.%s.properties",profiles[0]);            
            loader = new PropertiesLoader("properties/"+fileName);
        }else{            
            loader = new PropertiesLoader("properties/global.properties");
        }
    }

    public static String getConsoleBaseDir(){
        return loader.getProperty(CONSOLE_BASE_DIR);
    }

    public static String getPortalBaseDir(){
        return loader.getProperty(PORTAL_BASE_DIR);
    }
    
    /**
     * 获取FTP配置信息
     * @return
     */
    public static Properties getFtpConfig(){
    	return loader.getProperties();
    }
    
    public static String getFtpHost(){
    	return loader.getProperty(FTP_HOST);
    }
    public static Integer getFtpPort(){
    	return loader.getInteger(FTP_PORT);
    }
    public static String getFtpUser(){
    	return loader.getProperty(FTP_USER);
    }
    public static String getFtpPassword(){
    	return loader.getProperty(FTP_PASS);
    }
    public static String getImgPath(){
    	return loader.getProperty(IMAGE_SERVER);
    }
}
